package com.yunao.service.impl;

import com.yunao.dao.AlonereportDao;
import com.yunao.entity.AloneReport;
import com.yunao.service.AlonereportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AlonereportServiceImpl implements AlonereportService {

    @Autowired
    private AlonereportDao alonereportDao;

    @Override
    public List<AloneReport> findByUseridAndNeedReport(Integer userid, String needReport) {
        return alonereportDao.findAllByUserIdAndNeedReportNot(userid,needReport);
    }

    @Override
    public AloneReport findById(Integer aid) {
        if(alonereportDao.findById(aid).isPresent()){
            return alonereportDao.findById(aid).get();
        }
        return null;
    }

    @Override
    public void insertAloneReport(AloneReport aloneReport) {
        alonereportDao.save(aloneReport);
    }

    @Override
    public void updateOne(AloneReport aloneReport) {
        alonereportDao.saveAndFlush(aloneReport);
    }

    @Override
    public String countByUserIdAndName(Integer userid, String name) {
        return alonereportDao.countByUserIdAndName(userid,name);
    }

    @Override
    public List<AloneReport> findByUseridAndNeedReport(Integer userid, String needReport, Pageable pageable) {
        return alonereportDao.findAllByUserIdAndNeedReportNot(userid,needReport,pageable);
    }

    @Override
    public List<AloneReport> findAllByUserId(Integer userid,Pageable pageable) {
        return alonereportDao.findAllByUserId(userid,pageable);
    }

    @Override
    public void delete(Integer id) {
        alonereportDao.deleteById(id);
    }

    @Override
    public List<AloneReport> findByNeed(String need) {
        return alonereportDao.findAllByNeedReport(need);
    }

    @Override
    public List<AloneReport> findByNeedAndId(String need, Integer id) {
        return alonereportDao.findAllByNeedReportAndId(need,id);
    }

}
